refactor(file-browser): Granular item rendering and programmatic DOM list construction - #2723
Open
AuDevTist1C wants to merge 3 commits into
Open
refactor(file-browser): Granular item rendering and programmatic DOM list construction#2723AuDevTist1C wants to merge 3 commits into
AuDevTist1C wants to merge 3 commits into
Conversation
Isolate the file system rename operation into its own dedicated commit to preserve continuous history tracking within Git. Renaming `list.hbs` to `listItem.hbs` without altering any content ensures Git records this change as a 100% file rename. Decoupling this step prevents Git from misinterpreting subsequent structural template refactors as a destructive file deletion followed by the addition of an entirely new file. * **Template File Rename (`src/pages/fileBrowser/`):** * Renamed `src/pages/fileBrowser/list.hbs` to `src/pages/fileBrowser/listItem.hbs` with zero line changes (100% similarity score), guaranteeing clean `git blame` and file history continuity across structural revisions. (AI generated commit message)
…eholder
Overhaul the directory rendering logic in the file browser by replacing monolithic template compilation with programmatic DOM element construction and individual item parsing.
Previously, directory list rendering relied on a single template (`list.hbs`) that wrapped the outer `<ul>` element, handled list iteration (`{{#list}}`), and relied on the `mustache` package's built-in capability to render placeholder text if the element had no children when the `empty-msg` HTML attribute was provided.
This commit refactors the template down to a granular single-item scale and adds the empty state placeholder back explicitly via programmatic rendering. By splitting template rendering into granular helper functions (`createListEl`, `createListItemEl`, and `createPlaceholderEl`), directory rendering now builds list elements individually and explicitly appends a styled placeholder node whenever a directory contains no files or folders.
* **Template Scope Reduction (`src/pages/fileBrowser/listItem.hbs`):**
* Removed the enclosing `<ul class="list" id="list">` container tag and the surrounding `{{#list}}...{{/list}}` iteration block from the Handlebars template.
* Converted the file into a standalone item partial that takes an entry object and produces a single `<li>` element representing a file or directory row.
* **DOM Element Construction Helpers (`src/pages/fileBrowser/fileBrowser.js`):**
* Added `createListEl()` to dynamically generate the parent `<ul className="list" id="list">` element.
* Added `createListItemEl(obj)` to parse individual item objects through `mustache.render(_listItem, obj)` into single `HTMLLIElement` nodes.
* Added `createPlaceholderEl(msg)` to create dedicated empty-state DOM elements (`<div id="placeholder">{msg}</div>`).
* **Render Loop & Empty State Logic (`src/pages/fileBrowser/fileBrowser.js`):**
* Updated `render(dir)` to construct list containers programmatically and append rendered child elements via standard DOM iteration (`$list.appendChild(el)`).
* Re-implemented empty directory handling: if `list.length` is zero, a placeholder element containing the localized empty folder string is appended to the list, restoring the empty message functionality previously supplied via Mustache's `empty-msg` attribute.
* **Placeholder Layout Styling (`src/pages/fileBrowser/fileBrowser.scss`):**
* Defined CSS rules for `#placeholder` utilizing Flexbox (`display: flex`, `align-items: center`, `justify-content: center`) to ensure empty folder messages are centered within the file browser container.
(AI generated commit message)
Contributor
Greptile SummaryThe file browser now constructs its list container and empty-state placeholder programmatically while rendering each directory entry from a standalone item template.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
Render["render(dir)"] --> List["createListEl()"]
Render --> Check{"Directory has entries?"}
Check -->|Yes| Item["createListItemEl(item)"]
Item --> AppendItem["Append each LI to UL"]
Check -->|No| Placeholder["createPlaceholderEl(message)"]
Placeholder --> AppendPlaceholder["Append placeholder to UL"]
AppendItem --> Mount["Replace existing list and mount UL"]
AppendPlaceholder --> Mount
Reviews (3): Last reviewed commit: "fix" | Re-trigger Greptile |
AuDevTist1C
marked this pull request as ready for review
August 11, 2026 20:24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 Context & Motivation
Per #2500 (comment) regarding PR size and review complexity, this PR extracts the foundational DOM rendering refactor into a dedicated, self-contained pull request.
PR #2500 introduces navigation state management, skeleton UI feedback, and async safety routines. However, those additions directly depend on having granular DOM node control rather than compiling monolithic list templates. By isolating template scope reduction and DOM helper construction into this PR, we simplify code review and preserve Git history continuity before layering async navigation logic on top.
🛠️ Summary of Changes
This PR refactors directory list rendering in the file browser away from full-list Mustache template compilation into modular item construction helpers and programmatic DOM loops.
1. Continuous Git History Preservation
src/pages/fileBrowser/list.hbs➔src/pages/fileBrowser/listItem.hbs: Isolated the file system rename operation into its own dedicated commit with zero content alterations. This ensures Git records a 100% similarity score, preserving continuousgit blameand file history tracking across structural updates.2. Template Scope Granularity (
listItem.hbs)<ul class="list" id="list">wrapper element and the surrounding{{#list}}...{{/list}}iteration tag from the Handlebars template.<li>element representing an individual file or directory item.3. DOM Construction Helpers (
fileBrowser.js)Implemented explicit helper utilities in
fileBrowser.jsto modularize node creation:createListEl(): Generates and returns the parent<ul className="list" id="list">container.createListItemEl(obj): Renders item data viamustache.render(_listItem, obj)and parses the output into anHTMLLIElementnode.createPlaceholderEl(msg): Programmatically constructs dedicated empty-state nodes (<div id="placeholder">{msg}</div>).4. Render Loop & Restored Empty State (
fileBrowser.js)render(dir)to instantiate list containers programmatically and append rendered child elements via standard DOM iteration ($list.appendChild(el)).empty-msgattribute handling on the root list template. Under the new item-level workflow, explicit empty check logic was added: whenlist.lengthis zero,createPlaceholderEl(msg)appends the localized empty message element directly to the container.5. Layout Alignment (
fileBrowser.scss)#placeholderusing Flexbox (display: flex,align-items: center,justify-content: center) to guarantee empty directory placeholder messages are centered vertically and horizontally within the file browser body.🔍 Why Is This Refactor Necessary?
transition effects(not yet implemented), and async state safety.(PR name and description are AI generated (Gemini 3.6 Flash))